home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / libg_261.zip / libg_261 / libg++ / src / CursesW.h < prev    next >
C/C++ Source or Header  |  1994-10-24  |  14KB  |  596 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2.  
  3. /* 
  4. Copyright (C) 1989 Free Software Foundation
  5.     written by Eric Newton (newton@rocky.oswego.edu)
  6.  
  7. This file is part of the GNU C++ Library.  This library is free
  8. software; you can redistribute it and/or modify it under the terms of
  9. the GNU Library General Public License as published by the Free
  10. Software Foundation; either version 2 of the License, or (at your
  11. option) any later version.  This library is distributed in the hope
  12. that it will be useful, but WITHOUT ANY WARRANTY; without even the
  13. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  14. PURPOSE.  See the GNU Library General Public License for more details.
  15. You should have received a copy of the GNU Library General Public
  16. License along with this library; if not, write to the Free Software
  17. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #ifndef _CursesWindow_h
  21. #ifdef __GNUG__
  22. #pragma interface
  23. #endif
  24. #define _CursesWindow_h
  25.  
  26. #include   <_G_config.h>
  27. #if _G_HAVE_CURSES
  28. // Even many system which mostly have C++-ready header files,
  29. // do not have C++-ready curses.h.
  30. extern "C" {
  31. #include   <curses.h>
  32. }
  33.  
  34. /* SCO 3.2v4 curses.h includes term.h, which defines lines as a macro.
  35.    Undefine it here, because CursesWindow uses lines as a method.  */
  36. #undef lines
  37.  
  38. // "Convert" macros to inlines, if needed.
  39. #ifdef addch
  40. inline int (addch)(char ch)  { return addch(ch); }
  41. #undef addch
  42. #endif
  43. #ifdef addstr
  44. /* The (char*) cast is to hack around missing const's */
  45. inline int (addstr)(const char * str)  { return addstr((char*)str); }
  46. #undef addstr
  47. #endif
  48. #ifdef clear
  49. inline int (clear)()  { return clear(); }
  50. #undef clear
  51. #endif
  52. #ifdef clearok
  53. inline int (clearok)(WINDOW* win, int bf)  { return clearok(win, bf); }
  54. #undef clearok
  55. #else
  56. extern "C" int clearok(WINDOW*, int);
  57. #endif
  58. #ifdef clrtobot
  59. inline int (clrtobot)()  { return clrtobot(); }
  60. #undef clrtobot
  61. #endif
  62. #ifdef clrtoeol
  63. inline int (clrtoeol)()  { return clrtoeol(); }
  64. #undef clrtoeol
  65. #endif
  66. #ifdef delch
  67. inline int (delch)()  { return delch(); }
  68. #undef delch
  69. #endif
  70. #ifdef deleteln
  71. inline int (deleteln)()  { return deleteln(); }
  72. #undef deleteln
  73. #endif
  74. #ifdef erase
  75. inline int (erase)()  { return erase(); }
  76. #undef erase
  77. #endif
  78. #ifdef flushok
  79. inline int (flushok)(WINDOW* _win, int _bf)  { return flushok(_win, _bf); }
  80. #undef flushok
  81. #else
  82. #define _no_flushok
  83. #endif
  84. #ifdef getch
  85. inline int (getch)()  { return getch(); }
  86. #undef getch
  87. #endif
  88. #ifdef getstr
  89. inline int (getstr)(char *_str)  { return getstr(_str); }
  90. #undef getstr
  91. #endif
  92. #ifdef getyx
  93. inline void (getyx)(WINDOW* win, int& y, int& x) { getyx(win, y, x); }
  94. #undef getyx
  95. #endif
  96. #ifdef inch
  97. inline int (inch)()  { return inch(); }
  98. #undef inch
  99. #endif
  100. #ifdef insch
  101. inline int (insch)(char c)  { return insch(c); }
  102. #undef insch
  103. #endif
  104. #ifdef insertln
  105. inline int (insertln)()  { return insertln(); }
  106. #undef insertln
  107. #endif
  108. #ifdef leaveok
  109. inline int (leaveok)(WINDOW* win, int bf)  { return leaveok(win, bf); }
  110. #undef leaveok
  111. #else
  112. extern "C" int leaveok(WINDOW* win, int bf);
  113. #endif
  114. #ifdef move
  115. inline int (move)(int x, int y)  { return move(x, y); }
  116. #undef move
  117. #endif
  118. #ifdef refresh
  119. inline int (rfresh)()  { return refresh(); }
  120. #undef refresh
  121. #endif
  122. #ifdef scrollok
  123. inline int (scrollok)(WINDOW* win, int bf)  { return scrollok(win, bf); }
  124. #undef scrollok
  125. #else
  126. #ifndef hpux
  127. extern "C" int scrollok(WINDOW*, int);
  128. #else
  129. extern "C" int scrollok(WINDOW*, char);
  130. #endif
  131. #endif
  132. #ifdef standend
  133. inline int (standend)()  { return standend(); }
  134. #undef standend
  135. #endif
  136. #ifdef standout
  137. inline int (standout)()  { return standout(); }
  138. #undef standout
  139. #endif
  140. #ifdef wstandend
  141. inline int (wstandend)(WINDOW *win)  { return wstandend(win); }
  142. #undef wstandend
  143. #endif
  144. #ifdef wstandout
  145. inline int (wstandout)(WINDOW *win)  { return wstandout(win); }
  146. #undef wstandout
  147. #endif
  148. #ifdef winch
  149. inline int (winch)(WINDOW* win) { return winch(win); }
  150. #undef winch
  151. #endif
  152.  
  153. /* deal with conflicting macros in ncurses.h  which is SYSV based*/
  154. #ifdef box
  155. inline _G_box(WINDOW* win, chtype v, chtype h) {return box(win, v, h); }
  156. #undef box
  157. inline box(WINDOW* win, chtype v, chtype h) {return _G_box(win, v, h); }
  158. #endif
  159. #ifdef scroll
  160. inline (scroll)(WINDOW* win) { return scroll(win); }
  161. #undef scroll
  162. #endif
  163. #ifdef touchwin
  164. inline (touchwin)(WINDOW* win) { return touchwin(win); }
  165. #undef touchwin
  166. #endif
  167.  
  168. #ifdef mvwaddch
  169. inline int (mvwaddch)(WINDOW *win, int y, int x, char ch)
  170. { return mvwaddch(win, y, x, ch); }
  171. #undef mvwaddch
  172. #endif
  173. #ifdef mvwaddstr
  174. inline int (mvwaddstr)(WINDOW *win, int y, int x, const char * str)
  175. { return mvwaddstr(win, y, x, (char*)str); }
  176. #undef mvwaddstr
  177. #endif
  178. #ifdef mvwdelch
  179. inline int (mvwdelch)(WINDOW *win, int y, int x) { return mvwdelch(win, y, x);}
  180. #undef mvwdelch
  181. #endif
  182. #ifdef mvwgetch
  183. inline int (mvwgetch)(WINDOW *win, int y, int x) { return mvwgetch(win, y, x);}
  184. #undef mvwgetch
  185. #endif
  186. #ifdef mvwgetstr
  187. inline int (mvwgetstr)(WINDOW *win, int y, int x, char *str)
  188. {return mvwgetstr(win,y,x, str);}
  189. #undef mvwgetstr
  190. #endif
  191. #ifdef mvwinch
  192. inline int (mvwinch)(WINDOW *win, int y, int x) { return mvwinch(win, y, x);}
  193. #undef mvwinch
  194. #endif
  195. #ifdef mvwinsch
  196. inline int (mvwinsch)(WINDOW *win, int y, int x, char c)
  197. { return mvwinsch(win, y, x, c); }
  198. #undef mvwinsch
  199. #endif
  200.  
  201. #ifdef mvaddch
  202. inline int (mvaddch)(int y, int x, char ch)
  203. { return mvaddch(y, x, ch); }
  204. #undef mvaddch
  205. #endif
  206. #ifdef mvaddstr
  207. inline int (mvaddstr)(int y, int x, const char * str)
  208. { return mvaddstr(y, x, (char*)str); }
  209. #undef mvaddstr
  210. #endif
  211. #ifdef mvdelch
  212. inline int (mvdelch)(int y, int x) { return mvdelch(y, x);}
  213. #undef mvdelch
  214. #endif
  215. #ifdef mvgetch
  216. inline int (mvgetch)(int y, int x) { return mvgetch(y, x);}
  217. #undef mvgetch
  218. #endif
  219. #ifdef mvgetstr
  220. inline int (mvgetstr)(int y, int x, char *str) {return mvgetstr(y, x, str);}
  221. #undef mvgetstr
  222. #endif
  223. #ifdef mvinch
  224. inline int (mvinch)(int y, int x) { return mvinch(y, x);}
  225. #undef mvinch
  226. #endif
  227. #ifdef mvinsch
  228. inline int (mvinsch)(int y, int x, char c)
  229. { return mvinsch(y, x, c); }
  230. #undef mvinsch
  231. #endif
  232.  
  233. /*
  234.  *
  235.  * C++ class for windows.
  236.  *
  237.  *
  238.  */
  239.  
  240. class CursesWindow 
  241. {
  242. protected:
  243.   static int     count;           // count of all active windows:
  244.                                   //   We rely on the c++ promise that
  245.                                   //   all otherwise uninitialized
  246.                                   //   static class vars are set to 0
  247.  
  248.   WINDOW *       w;               // the curses WINDOW
  249.  
  250.   int            alloced;         // true if we own the WINDOW
  251.  
  252.   CursesWindow*  par;             // parent, if subwindow
  253.   CursesWindow*  subwins;         // head of subwindows list
  254.   CursesWindow*  sib;             // next subwindow of parent
  255.  
  256.   void           kill_subwindows(); // disable all subwindows
  257.  
  258. public:
  259.                  CursesWindow(WINDOW* &window);   // useful only for stdscr
  260.  
  261.                  CursesWindow(int lines,          // number of lines
  262.                               int cols,           // number of columns
  263.                               int begin_y,        // line origin
  264.                               int begin_x);       // col origin
  265.  
  266.                  CursesWindow(CursesWindow& par,  // parent window
  267.                               int lines,          // number of lines
  268.                               int cols,           // number of columns
  269.                               int by,             // absolute or relative
  270.                               int bx,             //   origins:
  271.                               char absrel = 'a'); // if `a', by & bx are
  272.                                                   // absolute screen pos,
  273.                                                   // else if `r', they are
  274.                                                   // relative to par origin
  275.                 ~CursesWindow();
  276.  
  277. // terminal status
  278.   int            lines(); // number of lines on terminal, *not* window
  279.   int            cols();  // number of cols  on terminal, *not* window
  280.  
  281. // window status
  282.   int            height(); // number of lines in this window
  283.   int            width();  // number of cols in this window
  284.   int            begx();   // smallest x coord in window
  285.   int            begy();   // smallest y coord in window
  286.   int            maxx();   // largest  x coord in window
  287.   int            maxy();   // largest  x coord in window
  288.  
  289. // window positioning
  290.   int            move(int y, int x);
  291.  
  292. // coordinate positioning
  293.   void           getyx(int& y, int& x);
  294.   int            mvcur(int sy, int ey, int sx, int ex);
  295.  
  296. // input
  297.   int            getch();
  298.   int            getstr(char * str);
  299.   int            scanw(const char *, ...);
  300.  
  301. // input + positioning
  302.   int            mvgetch(int y, int x);
  303.   int            mvgetstr(int y, int x, char * str);
  304.   int            mvscanw(int, int, const char*, ...);
  305.  
  306. // output
  307.   int            addch(const char ch);
  308.   int            addstr(const char * str);
  309.   int            printw(const char * fmt, ...);
  310.   int            inch();
  311.   int            insch(char c);
  312.   int            insertln();
  313.  
  314. // output + positioning
  315.   int            mvaddch(int y, int x, char ch);
  316.   int            mvaddstr(int y, int x, const char * str);
  317.   int            mvprintw(int y, int x, const char * fmt, ...);
  318.   int            mvinch(int y, int x);
  319.   int            mvinsch(int y, int x, char ch);
  320.  
  321. // borders
  322.   int            box(char vert, char  hor);
  323.  
  324. // erasure
  325.   int            erase();
  326.   int            clear();
  327.   int            clearok(int bf);
  328.   int            clrtobot();
  329.   int            clrtoeol();
  330.   int            delch();
  331.   int            mvdelch(int y, int x);
  332.   int            deleteln();
  333.  
  334. // screen control
  335.   int            scroll();
  336.   int            scrollok(int bf);
  337.   int            touchwin();
  338.   int            refresh();
  339.   int            leaveok(int bf);
  340. #ifndef _no_flushok
  341.   int            flushok(int bf);
  342. #endif
  343.   int            standout();
  344.   int            standend();
  345.  
  346. // multiple window control
  347.   int            overlay(CursesWindow &win);
  348.   int            overwrite(CursesWindow &win);
  349.  
  350.  
  351. // traversal support
  352.   CursesWindow*  child();
  353.   CursesWindow*  sibling();
  354.   CursesWindow*  parent();
  355. };
  356.  
  357.  
  358. inline int CursesWindow::begx()
  359. {
  360.   return w->_begx;
  361. }
  362.  
  363. inline int CursesWindow::begy()
  364. {
  365.   return w->_begy;
  366. }
  367.  
  368. inline int CursesWindow::maxx()
  369. {
  370.   return w->_maxx;
  371. }
  372.  
  373. inline int CursesWindow::maxy()
  374. {
  375.   return w->_maxy;
  376. }
  377.  
  378. inline int CursesWindow::height()
  379. {
  380.   return maxy() - begy() + 1;
  381. }
  382.  
  383. inline int CursesWindow::width()
  384. {
  385.   return maxx() - begx() + 1;
  386. }
  387.  
  388. inline int CursesWindow::box(char vert, char  hor)    
  389. {
  390.   return ::box(w, vert, hor); 
  391. }
  392.  
  393. inline int CursesWindow::overlay(CursesWindow &win)         
  394. {
  395.   return ::overlay(w, win.w); 
  396. }
  397.  
  398. inline int CursesWindow::overwrite(CursesWindow &win)       
  399. {
  400.   return ::overwrite(w, win.w); 
  401. }
  402.  
  403. inline int CursesWindow::scroll()                     
  404. {
  405.   return ::scroll(w); 
  406. }
  407.  
  408.  
  409. inline int CursesWindow::touchwin()                   
  410. {
  411.   return ::touchwin(w); 
  412. }
  413.  
  414. inline int CursesWindow::addch(const char ch)         
  415. {
  416.   return ::waddch(w, ch); 
  417. }
  418.  
  419. inline int CursesWindow::addstr(const char * str)     
  420. {
  421.   // The (char*) cast is to hack around prototypes in curses.h that
  422.   // have const missing in the parameter lists.  [E.g. SVR4]
  423.   return ::waddstr(w, (char*)str); 
  424. }
  425.  
  426. inline int CursesWindow::clear()                      
  427. {
  428.   return ::wclear(w); 
  429. }
  430.  
  431. inline int CursesWindow::clrtobot()                   
  432. {
  433.   return ::wclrtobot(w); 
  434. }
  435.  
  436. inline int CursesWindow::clrtoeol()                   
  437. {
  438.   return ::wclrtoeol(w); 
  439. }
  440.  
  441. inline int CursesWindow::delch()                      
  442. {
  443.   return ::wdelch(w); 
  444. }
  445.  
  446. inline int CursesWindow::deleteln()                   
  447. {
  448.   return ::wdeleteln(w); 
  449. }
  450.  
  451. inline int CursesWindow::erase()                      
  452. {
  453.   return ::werase(w); 
  454. }
  455.  
  456. inline int CursesWindow::getch()                      
  457. {
  458.   return ::wgetch(w); 
  459. }
  460.  
  461. inline int CursesWindow::getstr(char * str)           
  462. {
  463.   return ::wgetstr(w, str); 
  464. }
  465.  
  466. inline int CursesWindow::inch()                       
  467. {
  468.   return winch(w); 
  469. }
  470.  
  471. inline int CursesWindow::insch(char c)               
  472. {
  473.   return ::winsch(w, c); 
  474. }
  475.  
  476. inline int CursesWindow::insertln()                   
  477. {
  478.   return ::winsertln(w); 
  479. }
  480.  
  481. inline int CursesWindow::move(int y, int x)           
  482. {
  483.   return ::wmove(w, y, x); 
  484. }
  485.  
  486.  
  487. inline int CursesWindow::mvcur(int sy, int ey, int sx, int ex)
  488. {
  489.   return ::mvcur(sy, ey, sx,ex);
  490. }
  491.  
  492. inline int CursesWindow::mvaddch(int y, int x, char ch)
  493. {
  494.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddch(w, ch);
  495. }
  496.  
  497. inline int CursesWindow::mvgetch(int y, int x)
  498. {
  499.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetch(w);
  500. }
  501.  
  502. inline int CursesWindow::mvaddstr(int y, int x, const char * str)
  503. {
  504.   return (::wmove(w, y, x)==ERR) ? ERR : ::waddstr(w, (char*)str);
  505. }
  506.  
  507. inline int CursesWindow::mvgetstr(int y, int x, char * str)
  508. {
  509.   return (::wmove(w, y, x)==ERR) ? ERR : ::wgetstr(w, str);
  510. }
  511.  
  512. inline int CursesWindow::mvinch(int y, int x)
  513. {
  514.   return (::wmove(w, y, x)==ERR) ? ERR : ::winch(w);
  515. }
  516.  
  517. inline int CursesWindow::mvdelch(int y, int x)
  518. {
  519.   return (::wmove(w, y, x)==ERR) ? ERR : ::wdelch(w);
  520. }
  521.  
  522. inline int CursesWindow::mvinsch(int y, int x, char ch)
  523. {
  524.   return (::wmove(w, y, x)==ERR) ? ERR : ::winsch(w, ch);
  525. }
  526.  
  527. inline int CursesWindow::refresh()                   
  528. {
  529.   return ::wrefresh(w); 
  530. }
  531.  
  532. inline int CursesWindow::clearok(int bf)             
  533. {
  534.   return ::clearok(w,bf); 
  535. }
  536.  
  537. inline int CursesWindow::leaveok(int bf)             
  538. {
  539.   return ::leaveok(w,bf); 
  540. }
  541.  
  542. inline int CursesWindow::scrollok(int bf)            
  543. {
  544.   return ::scrollok(w,bf); 
  545. }
  546.  
  547. #ifndef _no_flushok
  548. inline int CursesWindow::flushok(int bf)            
  549. {
  550.   return ::flushok(w, bf); 
  551. }
  552. #endif
  553.  
  554. inline void CursesWindow::getyx(int& y, int& x)       
  555. {
  556.   ::getyx(w, y, x); 
  557. }
  558.  
  559. inline int CursesWindow::standout()                   
  560. {
  561.   return ::wstandout(w); 
  562. }
  563.  
  564. inline int CursesWindow::standend()                   
  565. {
  566.   return ::wstandend(w); 
  567. }
  568.  
  569. inline int CursesWindow::lines()                      
  570. {
  571.   return LINES; 
  572. }
  573.  
  574. inline int CursesWindow::cols()                       
  575. {
  576.   return COLS; 
  577. }
  578.  
  579. inline CursesWindow* CursesWindow::child()
  580. {
  581.   return subwins;
  582. }
  583.  
  584. inline CursesWindow* CursesWindow::parent()
  585. {
  586.   return par;
  587. }
  588.  
  589. inline CursesWindow* CursesWindow::sibling()
  590. {
  591.   return sib;
  592. }
  593.  
  594. #endif /* _G_HAVE_CURSES */
  595. #endif
  596.